<!DOCTYPE html>
<html lang="en">
{include file='index/header' title='音乐之家 留言板'}
{include file='index/index_header'}

<script type="text/javascript">
    $(document).ready(function(){
        $("#jMenu").jMenu();
    })
    $(function() {
        $(".input-date").datepicker({
            dateFormat: "yy-mm-dd"
        })
    })
</script>
<body>
<!--<div id="fireworks">-->
{include file='index/effect_header'}
<!--</div>-->
<div id="controller">
    <!--修改密码 弹窗 -->
    {include file='index/change_pwd'}
    {include file='index/personal'}
    {include file='message/user_info'}
    <div class="container" style="margin-top:10px;">
        {include file='index/contact'}
    </div>
    <div class="container" style="margin-top:10px;" >
        <input v-model="user"   type="text" class="input-text input-180" placeholder="请输入用户名" autocomplete="off">

        <button type="submit" :issend="!disabled"  @click="getData" class="input-button input-submit">查询</button>

    </div>
    <div class="container" style="margin-top:10px;" >
        <table width="100%">
            <colgroup width="2%"></colgroup>
            <colgroup width="3%"></colgroup>
            <colgroup width="4%"></colgroup>
            <colgroup width="3%"></colgroup>
            <colgroup width="6%"></colgroup>
            <colgroup width="4%"></colgroup>
            <colgroup width="7%"></colgroup>
            <colgroup width="4%"></colgroup>

            <thead >
            <tr class="title" >
                <th>序号</th>
                <th>用户名</th>
                <th>用户等级</th>
                <th>邮箱</th>
                <th>职位</th>
                <th>管理员/注册用户</th>
                <th>创建日期</th>
                <th>操作</th>

            </tr>
            </thead>

            <tbody class="center">
            <tr  v-for="(item,index) in user_list" >
                <td >{{index + 1}}</td>
                <td >{{item.username}}</td>
                <td >{{item.level_mes}}</td>
                <td >{{item.email}}</td>
                <td>
                    <a style="cursor: pointer" :title="item.content"  type="submit" @click="readData2(item.id,username)" >
                        {{item.nick_name}}

                    </a>

                </td>
                <td>{{item.level ==0 ? '管理员' :'注册用户'}}</td>
                <td>{{item.add_time ? item.add_time :'-'}}</td>

                <td style="display: flex;width: 100%;height: 10%;justify-content:space-around">
                    <button  type="submit" @click="editUser(item.user_id)" class="btn1 btn1-danger">编辑</button>
                    <button  type="submit" @click="deleteUser(item.user_id)" class="btn btn-danger">删除</button>
                    <button  type="submit" @click="verify(item,item.user_id)" class="btn1 btn1-danger" :disabled="!item.condition"  :style="{cursor:item.condition==1 ? 'pointer' : 'not-allowed'}"  :style="{color:item.condition==0 ? 'white' : 'black'}">{{item.condition ==0 ? '已认证' : '未认证'}}</button>

                    <!--                    <button   :disabled="!item.change_auth" @click="changeData(item.id)" class="btn1 btn1-danger" :style="{cursor:item.change_auth ? 'pointer' : 'not-allowed'}">修改</button>-->
                    <!--                <a  v-if="disabled"  :href="'change/'+item.id" class="btn1 btn1-danger">修改</a>-->
                    <!--                    <button  :disabled="true"   class="btn1 btn1-danger" :style="{cursor: 'not-allowed'}">回复</button>-->

                </td>
            </tr>
            </tbody>
        </table>
        <div class="nocontent">
            <span v-show='!user_list.length' v-if="!table_show" style="font-size: 18px;text-align: center">暂无内容......</span>
        </div>
        <page-turn2 :page="page" :pagesum="pageSum" :sum="sum" @update="changelist"></page-turn2>

    </div>


</div>
<!--<img src="__STATIC__/images/1.gif" id="im" alt="" />-->
<!--<script type="text/javascript">-->
<!--    var imobj = document.getElementById("im");-->
<!--    document.onmousemove = function (e) {-->
<!--        imobj.style.left = e.clientX + 25 + "px";-->
<!--        imobj.style.top = e.clientY + "px";-->
<!--    }-->
<!--</script>-->

<!--<div class="box">-->
<!--    <ul class="minbox">-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--    </ul>-->
<!--    <ol class="maxbox">-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--        <li></li>-->
<!--    </ol>-->
<!--</div>-->
</body>

<script >
    var controller = new Vue({
        el : '#controller',
        data : {
            title : '',
            startDate : '',
            endDate:'',
            data_list: {

            },
            user_list: {

            },
            user:'',
            // PAGE_NUM: 0,
            id:'',
            /*当前页*/
            page: 1,
            /*总页数*/
            pageSum: 1,
            /*总条数*/
            sum: 1,
            disabled:false,
            table_show: false,
            start:'',
            limit:'',
            username: localStorage.mUser,
            status:'',
            level:true,
            auth_level:true,
            changeP:false,
            //个人信息
            personal_button:false,
            singular:{
                oldPWD:'',
                newPWD:'',
                newPWDr:'',
            },
            //编辑用户信息
            user_info:false,
            singular2:{
                id:'',
                username:'',
                email:'',
                nick_name:'',
            },
            personal_list:{},
            module:'',
            //审核
            pass: '',
        },
        created: function() {
            // _self.no= GetQueryString('id')
            var _self = this;
            _self.online()
            _self.getData()
        },
        // mounted() {
        //     // 关闭浏览器窗口的时候清空浏览器缓存在localStorage的数据
        //     window.onbeforeunload = function (e) {
        //         var storage = window.localStorage;
        //         storage.clear()
        //     }
        //
        // },
        methods : {
            online:function() {
                var _self = this;
                libs.ajax('index/index/checkOnline', {

                },function (result) {
                    if(result.status==1)
                    {
                        alert('您已离线，请登录！');
                        localStorage.clear();
                        window.location.href = '/login'
                    }
                })
            },
            // getData: function() {
            //     var _self = this;
            //     _self.startDate = $('#startDate').val() || ''
            //     _self.endDate = $('#endDate').val() || ''
            //     _self.disabled = false
            //     _self.table_show = false
            //     libs.ajax('index/index/getArticalInfo', {
            //         title:_self.title,
            //         startDate:_self.startDate,
            //         endDate:_self.endDate,
            //         start: (_self.page - 1) * 30,
            //         limit: 30,
            //         module:_self.module,
            //         pass:_self.pass,
            //         private:1,
            //         label:1103,
            //     }, function(result) {
            //         _self.data_list =  []
            //         // _self.pageSum =  1
            //         // _self.sum =  0
            //
            //         if(result.status == 0)
            //         {
            //             _self.level = result.level
            //             if(result.auth_level == 0)
            //             {
            //                 _self.auth_level = false
            //             }
            //             _self.disabled = true
            //             _self.table_show = true
            //             _self.data_list = result.data.list
            //             _self.status = result.status
            //             _self.pageSum = result.data.page.total_page
            //             _self.sum = result.data.page.total_num
            //
            //         }
            //
            //     })
            // },
            getData: function() {
                var _self = this;
                _self.disabled = false
                _self.table_show = false
                libs.ajax('index/message/getUserInfo', {
                    username:_self.user,
                    start: (_self.page - 1) * 30,
                    limit: 30,
                }, function(result) {

                    if(result.status == 0)
                    {
                        _self.level = result.level
                        if(result.auth_level == 0)
                        {
                            _self.auth_level = false
                        }
                        _self.disabled = true
                        _self.table_show = true
                        _self.user_list = result.list
                        _self.pageSum = result.page.total_page
                        _self.sum = result.page.total_num
                    }

                })
            },
            deleteUser: function(id) {
                this.online();
                if (!confirm('确认删除吗？')) return;

                libs.ajax('index/message/deleteUser', {
                    user_id:id
                }, function(result) {
                    alert(result.msg)
                    location.reload();

                })
            },
            changeData: function(id) {
                libs.ajax('index/index/change_html', {
                    id:id
                }, function(result) {
                    if(result.status ==0)
                    {
                        window.location.href='change/'+id
                    }
                    else if(result.status ==1)
                    {
                        alert(result.msg);
                        setTimeout(gotoindex,1000);
                        function gotoindex() {
                            window.location.href = '/login'
                        }
                    }

                })
            },
            readData2: function(id,username) {
                libs.ajax('', {
                }, function() {
                    window.location.href='readData/'+id+'/name/'+username
                })
            },
            changelist: function (val) {
                this.page = val
                this.getData()
            },

            dologout: function() {
                if (!confirm('您确定退出吗?')) return;
                libs.ajax('index/login/DoLogout', {
                }, function(result) {
                    alert(result.msg)
                    if(result.status == 0)
                    {
                        localStorage.clear();
                        window.location.href='/'
                    }

                })
            },
            send: function() {
                var _self = this;

                if(!_self.singular.oldPWD || !_self.singular.newPWD || !_self.singular.newPWDr){
                    alert('表单不能为空')
                    return;
                }

                if (_self.singular.newPWD.length < 6 || _self.singular.newPWD.length > 20) {
                    alert("密码长度必须为6-20位，请重新输入！");
                    return;
                }

                if (_self.singular.newPWD != _self.singular.newPWDr) {
                    alert("新设置密码两次不一致，请重新输入！");
                    return;
                }

                libs.ajax('index/regist/ChangePassword', {
                    old_pwd : _self.singular.oldPWD,
                    new_pwd : _self.singular.newPWD,
                    new_pwd_a : _self.singular.newPWDr
                }, function(result) {
                    alert(result.msg)
                    if(result.status == 0){
                        localStorage.clear()
                        top.location.href = '/'
                    }
                })
            },
            send_user:function()
            {
                var _self = this;
                if(!_self.singular2.username && !_self.singular2.email && !_self.singular2.nick_name)
                {
                    alert("请输入任何一项以更新！");
                    return;
                }

                libs.ajax('index/message/changeUser', {
                    id:_self.singular2.id,
                    username : _self.singular2.username,
                    email : _self.singular2.email,
                    nick_name : _self.singular2.nick_name
                }, function(result) {

                    if(result.status == 0){
                        alert(result.msg)
                        location.reload()
                    }
                })
            },
            changePwd(){
                this.changeP=true;
                this.singular={}
            },
            editUser(id){
                this.user_info=true;
                this.singular2={
                        id:id,
                        username:'',
                        email:'',
                        nick_name:'',
                }
            },
            /*个人信息接口*/
            personal(){
                var _self = this;
                this.personal_button=true;
                libs.ajax('index/index/personal_info', {
                }, function(result) {
                    _self.personal_list = result.data;
                    console.log(_self.personal_list);
                })
            },
            /*回复 开关*/
            closed: function (item, id, state1) {
                if(state1 == 1)
                {
                    var mes = '是否开启留言回复功能？';
                }
                else
                {
                    var mes = '是否停用留言回复功能？';
                }
                if (!confirm(mes)) return;
                var _self = this;
                var state = state1 == '0' ? '1' : '0'
                libs.ajax('index/message/closeReply', {
                    id: id,
                    state: state
                }, function (result) {
                    if (result.status == 0) {
                        item.op_auth = state
                    } else {
                        alert(result.msg)
                    }
                })
            },
            /*私密 开关*/
            closed01: function (item, id, private) {
                if(private ==1)
                {
                    var mes = '是否开放留言？';
                }
                else
                {
                    var mes = '是否对留言私密？';
                }
                if (!confirm(mes)) return;
                var _self = this;
                var private = private == '0' ? '1' : '0'
                libs.ajax('index/message/closePrivate', {
                    id: id,
                    private: private
                }, function (result) {
                    if (result.status == 0) {
                        item.private = private
                    } else {
                        alert(result.msg)
                    }
                })
            },
            verify:function(item,id) {
                var mes = '确认审核通过？';
                if (!confirm(mes)) return;
                libs.ajax('index/message/passPeople', {
                    user_id: id,
                }, function (result) {
                    if(result.status==0)
                    {
                        alert(result.msg)
                        item.condition = 0;
                        location.reload();
                    }


                })
            },

        }
    })

</script>
</html>
